from urllib.parse import urlencode
from urllib.request import Request, urlopen

if __name__ == '__main__':
    url = "https://httpbin.org/post"

    form = {
        "username":"abc",
        "password":123456,
    }

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
    }

    data = urlencode(form).encode("utf-8")
    # 构建请求对象
    req = Request(url=url, data=data, headers=headers)
    resp = urlopen(req)

    content = resp.read()
    result = content.decode("utf-8")
    print(result)


